const BASEURL = 'http://localhost:3000/books/';

// 将相同的部分抽象成 一个对象
let request = {
  get(url){
    return new Promise( (resolve,reject) => {
      wx.request({
        url,
        success: (res) => {
          resolve(res)
        }
      })
    })
  }
}

const getBookList = function(){
  return new Promise( (resolve,reject) => {
    wx.request({
      url: BASEURL,
      success: (res) => {
        console.log(res);
        resolve(res)
      }
    })
  })
}

const getBookById = function(id){
  return new Promise( (resolve,reject) => {
    wx.request({
      url: BASEURL + id,
      success:(res) => {
        // console.log(res)
        let { data } = res;
        resolve(data);
      }
    })
  })
}
module.exports = {
  getBookList,
  getBookById
}